package com.qili.service.supplier.impl;

import com.qili.base.mapper.BaseMapper;
import com.qili.base.service.impl.BaseServiceImpl;
import com.qili.entity.base.BaseDict;
import com.qili.entity.supervisor.ProjectAdmin;
import com.qili.entity.supervisor.ProjectNotice;
import com.qili.entity.supervisor.SupervisorProjectFormsData;
import com.qili.entity.supplier.ProjectPlace;
import com.qili.entity.supplier.ProjectPlaceChange;
import com.qili.entity.supplier.SupplierProject;
import com.qili.entity.supplier.SupplierProjectAccept;
import com.qili.entity.supplier.dto.ProjectPlaceDTO;
import com.qili.entity.supplier.dto.SupplierProjectChangeDTO;
import com.qili.entity.supplier.dto.SupplierProjectDTO;
import com.qili.entity.sys.SysRegion;
import com.qili.entity.sys.SysUser;
import com.qili.entity.sys.dto.SysUserDTO;
import com.qili.mapper.supervisor.SupervisorProjectFormsDataMapper;
import com.qili.mapper.supplier.SupplierProjectMapper;
import com.qili.service.base.BaseDictService;
import com.qili.service.supervisor.ProjectAdminService;
import com.qili.service.supervisor.ProjectNoticeServie;
import com.qili.service.supplier.ProjectPlaceChangeService;
import com.qili.service.supplier.ProjectPlaceService;
import com.qili.service.supplier.SupplierProjectManagerService;
import com.qili.util.BeanUtil;
import com.qili.util.DateUtil;
import com.qili.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.List;

/**
 * @author zhaoyongke
 * @date 2021/3/13
 * @description
 */
@Service
public class SupplierProjectManagerServiceImpl  extends BaseServiceImpl<SupplierProject,String> implements SupplierProjectManagerService {

    @Autowired
    private SupplierProjectMapper supplierProjectMapper;
    @Autowired
    private ProjectPlaceService projectPlaceService;
    @Autowired
    ProjectPlaceChangeService projectPlaceChangeService;
    @Autowired
    ProjectNoticeServie  projectNoticeServie;

    @Autowired
    BaseDictService baseDictService;





    @Override
    public BaseMapper<SupplierProject, String> getMappser() {
        return supplierProjectMapper;
    }

    @Autowired
    public List<SupplierProjectDTO> selectProject(SupplierProjectDTO dto){
       return    supplierProjectMapper.selectProject(dto);
    };

    @Autowired
    public List<SupplierProjectDTO> selectMyProjectList(SupplierProjectDTO dto){
        return    supplierProjectMapper.selectMyProjectList(dto);
    };
    @Autowired
    public List<SupplierProjectDTO> selectMyProjectListApp(SupplierProjectDTO dto){
        return    supplierProjectMapper.selectMyProjectListApp(dto);
    };
    @Autowired
    public List<SupplierProjectDTO> selectProjectChangeList(SupplierProjectDTO dto){
        return    supplierProjectMapper.selectProjectChangeList(dto);
    };
    @Autowired
    public  List<SupplierProjectDTO> selectProjectChangeListApp(SupplierProjectDTO dto){
        return    supplierProjectMapper.selectProjectChangeListApp(dto);

    }
    /**
    * @Author:zhaoyongke
    * @Description: 查询没有应接记录的项目
    * @Date:13:21 2021/4/12
    */
    @Autowired
    public  List<SupplierProjectDTO> selectMyProjectListNotAccept(SupplierProjectDTO dto){
        List<SupplierProjectDTO> supplierProjectDTOS = supplierProjectMapper.selectMyProjectListNotAccept(dto);
        return  supplierProjectDTOS;
    }




    /**
     * @Author:zhaoyongke
     * @Description: 发送需方
     * @param project
     * @Date:14:30 2021/4/7
     */
    @Override
    public void sendNoticeToXf(SupplierProject project, String days){
        ProjectNotice notice = new ProjectNotice();
        notice.setLinkId(project.getSupProjectId());
        notice.setIsView("0");
        notice.setSendTo(project.getCreateBy());
        notice.setTitle("您发布的" + project.getProjectName() + "项目，" + days + "日内无人应接，系统建议调整服务费或招标截止时间，请确认");
        notice.setNoticeType("104");// 外部单位 x天 无应接 提醒
        notice.setApplicantType("002");// 供需
        notice.setContent(project.getProjectName());
        notice.setCreateDate(DateUtil.getCurrentDateString());
        projectNoticeServie.insertSelective(notice);
    }

    /**
     * @Author:zhaoyongke
     * @Description: 给需方发送议价消息
     * @param project
     * @param accept
     * @Date:13:11 2021/4/13
     */

    @Override
    public void sendNoticeToYj(SupplierProject project, SupplierProjectAccept accept,String remark){


        List<BaseDict> typeListSsbl = baseDictService.selectByTypeCode("NBXT001");
        String xvalue = "";
        if (typeListSsbl.size() > 0) {
            BaseDict bzjbl = typeListSsbl.get(0);
            xvalue = bzjbl.getBadtLevel1();
        }
        ProjectNotice notice = new ProjectNotice();
        notice.setLinkId(project.getSupProjectId());
        notice.setIsView("0");
        notice.setSendTo(accept.getAcceptBy());
        notice.setTitle("您应接的" + project.getProjectName() + "项目进入议价环节，请填写您接受的最低实施费用,所有应接人费用提交或"+xvalue+"日后将自动推荐");
        notice.setNoticeType("106");// 议价通知
        notice.setApplicantType("002");// 供需
        notice.setContent(project.getProjectName());
        notice.setCreateDate(DateUtil.getCurrentDateString());
        notice.setRemark(remark);
        projectNoticeServie.insertSelective(notice);
    }

    






    /**
     * @Author:zhaoyongke
     * @Description:添加实施地点
     * @param supplierProjectDTO
     * @param project
     * @Date:17:15 2021/3/22
     */
    @Override
    public void addPalce(SupplierProjectDTO supplierProjectDTO, SupplierProject project )  throws  Exception {
        List<ProjectPlaceDTO> projectPlacedtos = supplierProjectDTO.getProjectPlacedtos();
        for (int i = 0; i <projectPlacedtos.size() ; i++) {
            ProjectPlaceDTO dto= projectPlacedtos.get(i);
            ProjectPlace  place=new ProjectPlace();
            BeanUtil.copyNotNullBean(dto, place);
            place.setType("001");// 001 实施地点 002 人员要求地点
            place.setSupProjectId(project.getSupProjectId());
            projectPlaceService.insertSelective(place);
        }
    }
    /**
     * @Author:zhaoyongke
     * @Description: 人员要求地点
     * @param supplierProjectDTO
     * @param project
     * @Date:17:23 2021/3/22
     */
    @Override
    public void addPersonPalce(SupplierProjectDTO supplierProjectDTO, SupplierProject project )  throws  Exception {
        List<ProjectPlaceDTO> personPlacedtos = supplierProjectDTO.getPersonPlacedtos();
        for (int i = 0; i <personPlacedtos.size() ; i++) {
            ProjectPlaceDTO dto= personPlacedtos.get(i);
            if(StringUtil.isNotBlank(dto.getProvince())){
                ProjectPlace place=new ProjectPlace();
                BeanUtil.copyNotNullBean(dto, place);
                place.setType("002");// 001 实施地点 002 人员要求地点
                place.setSupProjectId(project.getSupProjectId());
                projectPlaceService.insertSelective(place);
            }

        }
    }

    @Override
    public  List<SupplierProjectDTO> selectListGx(SupplierProjectDTO dto){
          return  supplierProjectMapper.selectListGx( dto);
    }
    @Override
    public  Integer selectMaxOrderByPro(){
        return  supplierProjectMapper.selectMaxOrderByPro();
    }

    @Override
    public List<SupplierProjectDTO> selectListApp(SupplierProjectDTO dto){
        return  supplierProjectMapper.selectListApp( dto);

    }
    @Override
    public List<SupplierProjectDTO> selectProjectApp(SupplierProjectDTO dto){
        return  supplierProjectMapper.selectProjectApp( dto);

    }







}
